<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  
    
      
    

    
  

  

  
    
      
    

    
  

  
    
      
    

    
  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Microsoft YaHei:300,300italic,400,400italic,700,700italic|Georgia:300,300italic,400,400italic,700,700italic|Lobster Two:300,300italic,400,400italic,700,700italic|consolas:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Openstack,Kolla,安装部署," />





  <link rel="alternate" href="/atom.xml" title="一本正经的小马" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/images/favicon1.ico?v=5.1.0" />






<meta name="description" content="2014年下半年，OpenStack基金会已经意识到Docker对OpenStack可能造成的威胁，研究OpenStack和Docker如何并存迫在眉睫，在2015年的温哥华峰会上，推出了3个项目：  kolla：把OpenStack放到容器里面，部署OpenStack Magnum： 在OpenStack平台上面部署容器，后来改成COE(Container Orchestration Engin">
<meta name="keywords" content="Openstack,Kolla,安装部署">
<meta property="og:type" content="article">
<meta property="og:title" content="Kolla多节点物理机部署OpenStack">
<meta property="og:url" content="https://www.hanbert.cn/2017/10/03/Kolla多节点物理机部署OpenStack/index.html">
<meta property="og:site_name" content="一本正经的小马">
<meta property="og:description" content="2014年下半年，OpenStack基金会已经意识到Docker对OpenStack可能造成的威胁，研究OpenStack和Docker如何并存迫在眉睫，在2015年的温哥华峰会上，推出了3个项目：  kolla：把OpenStack放到容器里面，部署OpenStack Magnum： 在OpenStack平台上面部署容器，后来改成COE(Container Orchestration Engin">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://img.blog.csdn.net/20160205085614730">
<meta property="og:image" content="http://img.blog.csdn.net/20171002195129769?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHVveGl1anVl/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">
<meta property="og:updated_time" content="2017-10-03T04:16:14.055Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Kolla多节点物理机部署OpenStack">
<meta name="twitter:description" content="2014年下半年，OpenStack基金会已经意识到Docker对OpenStack可能造成的威胁，研究OpenStack和Docker如何并存迫在眉睫，在2015年的温哥华峰会上，推出了3个项目：  kolla：把OpenStack放到容器里面，部署OpenStack Magnum： 在OpenStack平台上面部署容器，后来改成COE(Container Orchestration Engin">
<meta name="twitter:image" content="http://img.blog.csdn.net/20160205085614730">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://www.hanbert.cn/2017/10/03/Kolla多节点物理机部署OpenStack/"/>





  <title> Kolla多节点物理机部署OpenStack | 一本正经的小马 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  







  <script type="text/javascript">
    (function() {
      var hm = document.createElement("script");
      hm.src = "//tajs.qq.com/stats?sId=61405345";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">一本正经的小马</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">假装不正经</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-essay">
          <a href="/categories/随笔" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            随笔
          </a>
        </li>
      
        
        <li class="menu-item menu-item-study">
          <a href="/categories/学习" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-paper-plane"></i> <br />
            
            学习
          </a>
        </li>
      
        
        <li class="menu-item menu-item-other">
          <a href="/categories/杂记" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-list"></i> <br />
            
            杂记
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocapitalize="off" autocomplete="off" autocorrect="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://www.hanbert.cn/2017/10/03/Kolla多节点物理机部署OpenStack/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="小马">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一本正经的小马">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Kolla多节点物理机部署OpenStack
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-03T01:42:57+08:00">
                2017-10-03
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/学习/" itemprop="url" rel="index">
                    <span itemprop="name">学习</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a class="cloud-tie-join-count" href="/2017/10/03/Kolla多节点物理机部署OpenStack/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count join-count" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2017/10/03/Kolla多节点物理机部署OpenStack/" class="leancloud_visitors" data-flag-title="Kolla多节点物理机部署OpenStack">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数 </span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>2014年下半年，OpenStack基金会已经意识到Docker对OpenStack可能造成的威胁，研究OpenStack和Docker如何并存迫在眉睫，在2015年的温哥华峰会上，推出了3个项目：</p>
<ul>
<li>kolla：把OpenStack放到容器里面，部署OpenStack</li>
<li>Magnum： 在OpenStack平台上面部署容器，后来改成COE(Container Orchestration Engine)</li>
<li>Solum：利用Docker来实现CI(Continuous Integration)/CD(Continuous Delivery)</li>
</ul>
<a id="more"></a>
<p>这就是当初基金会的设想，只不过经过2年的发展，目前就Kolla项目是最靠谱的。Magnum修改了自己的方向，并且带来的价值不大。Solum已经基本快要死掉了。</p>
<p>目前依据OpenStack的传统，Kolla项目被拆分成了三个项目：</p>
<ul>
<li>Kolla：主要负责OpenStack各个组件Docker镜像的制作</li>
<li>Kolla-Ansible：负责容器的管理配置，即OpenStack的部署，以Ansible作为编排引擎</li>
<li>Kolla-Kubernetes：和上面功能一样，只不过是以Kubernetes作为编排引擎</li>
</ul>
<p>Kolla项目自诞生以来，短短一年内投入生产环境，真正放到生产环境是在Mitaka版本。又经过了一年的完善，终于在Ocata版本，做到了一个很完善的地步。</p>
<p>Kolla的优势和使用场景，体现在如下几个方面：</p>
<ul>
<li>原子性的升级或者回退OpenStack部署；</li>
<li>基于组件升级OpenStack；</li>
<li>基于组件回退OpenStack；</li>
</ul>
<p>Kolla的最终目标是为OpenStack的每一个服务都创建一个对应的Docker Image，通过Docker Image将升级的粒度减小到Service级别，从而使升级时，对OpenStack影响能达到最小，并且一旦升级失败，也很容易回滚。升级只需要三步：Pull新版本的容器镜像，停止老版本的容器服务，然后启动新版本容器。回滚也不需要重新安装包了，直接启动老版本容器服务就行，非常方便。</p>
<p>Kolla使用到的技术如下：</p>
<ul>
<li>Docker</li>
<li>Ansible</li>
<li>Python</li>
<li>Docker-py</li>
<li>Jinja2</li>
</ul>
<blockquote>
<p><strong><em>Note：</em></strong><br>很多对Docker不熟悉人，以为把OpenStack放到Docker里，虚拟机也是跑在Docker里。其实这是误解。Kolla仅仅是把OpenStack各个服务的进程，放到Docker里而已。以前的vm怎么运行，现在还是怎么运行，没做任何的改变。</p>
</blockquote>
<h4 id="一、Kolla部署OpenStack的架构"><a href="#一、Kolla部署OpenStack的架构" class="headerlink" title="一、Kolla部署OpenStack的架构"></a>一、Kolla部署OpenStack的架构</h4><p>如下图所看到，通过Kolla部署OpenStack能够实现，全组件HA(High Available)，其中，像其他OpenStack部署项目一样，对于MySQL的HA方案，默认采用的均是Galera。</p>
<p><img src="http://img.blog.csdn.net/20160205085614730" alt="kolla-ansible/specs/ha.svg"></p>
<h4 id="二、前期准备"><a href="#二、前期准备" class="headerlink" title="二、前期准备"></a>二、前期准备</h4><p>目前Kolla能够在Ubuntu和Centos两种Linux发行版上部署OpenStack，本次部署使用Centos7，OpenStack组件Nova，Cinder，Swift后端存储使用Ceph，Glance理论上后端存储也可以采用Ceph，但是采用Ceph作为后端存储的话，Glance的镜像格式必须是<code>raw</code>，目前主流镜像格式<code>img</code>、<code>qcow2</code>都需要转换为<code>raw</code>格式才能够正常使用，但是<code>raw</code>镜像不支持快照。可以自行搜索这些镜像格式之间的区别。具体基础环境要求如下：</p>
<ul>
<li>物理机最小配置：8 GB 内存，40 GB 存储</li>
<li>Centos7 操作系统，最小化安装，最好根据自己规划，在安装过程中及时更改主机名</li>
<li>最少2块网卡，此处部署使用3块，其中一个网卡是万兆网卡</li>
<li>数据盘与系统盘分离，至少1块数据盘，理想状态3块数据盘</li>
<li>至少保证部署机有<code>root</code>登陆权限，其余节点可以视情况而定</li>
</ul>
<blockquote>
<p><strong><em>Reference:</em></strong></p>
<ul>
<li>QCOW2/RAW/qemu-img 概念浅析: <a href="http://blog.csdn.net/Jmilk/article/details/69418999?locationNum=5&amp;fps=1" target="_blank" rel="external">http://blog.csdn.net/Jmilk/article/details/69418999?locationNum=5&amp;fps=1</a></li>
<li>qcow2、raw、vmdk等镜像格式的比较和基本转换: <a href="http://blog.chinaunix.net/uid-14735472-id-4220089.html" target="_blank" rel="external">http://blog.chinaunix.net/uid-14735472-id-4220089.html</a></li>
</ul>
</blockquote>
<h4 id="三、网络环境准备"><a href="#三、网络环境准备" class="headerlink" title="三、网络环境准备"></a>三、网络环境准备</h4><p>本次部署，使用一台单独的48口交换机，因为采用了三个网卡，故在交换机上划分出了三个网段：</p>
<ul>
<li>Admin Network：部署过程中各节点通信，部署完成后OpenStack各组件间通信，能够连接互联网</li>
<li>Public Network：给OpenStack平台上的VM提供Floating IP以使其能够正常远程SSH和连接网络，能够连接互联网</li>
<li>Storage Network：Ceph节点间通信和数据传输的网段，内网网段，与互联网隔离</li>
</ul>
<p>本次部署三个网卡与三个网段的对应的情况如下：</p>
<ul>
<li>em1：连接到Admin Network，提前在网卡上配置好IP地址，确保能够远程SSH，且能够连接互联网</li>
<li>em2：连接到Pubic Network，只需要把网上连接到相应Port上，网卡状态为UP即可，不需要配置IP</li>
<li>p5p2：连接到 Storage Network，万兆网卡，需要提前配置一个内网地址段IP确保各个节点间能通信</li>
</ul>
<blockquote>
<p><strong><em>Note:</em></strong></p>
<ul>
<li>Public Network需要提前划分出一个地址段，预留足够的IP地址给OpenStack的VM使用</li>
<li>em2网卡一定不要配置IP地址</li>
<li>p5p2网卡不要配置<code>GateWay</code>，否则可能会与em1网卡的<code>Gateway</code>冲突，导致该主机不能够正常联网</li>
</ul>
</blockquote>
<h4 id="四、部署规划"><a href="#四、部署规划" class="headerlink" title="四、部署规划"></a>四、部署规划</h4><p>本次部署共12个节点，其中3个<code>controller</code>节点，分别命名为：controller1，controller2，controller3；9个<code>compute</code>节点，分别命名为：compute1~9；其中一台<code>controller</code>节点还承担<strong>Kolla部署机</strong>角色，具体角色划分如下：</p>
<ul>
<li>Kolla部署机：controller1</li>
<li>OpenStack镜像本地源服务器：controller1</li>
<li>3台controller节点：controller1~3</li>
<li>9台compte节点：compute1~9</li>
<li>Ceph的OSD节点：controller1~3，compute1~9的所有的数据盘</li>
</ul>
<h4 id="五、配置免密登陆"><a href="#五、配置免密登陆" class="headerlink" title="五、配置免密登陆"></a>五、配置免密登陆</h4><p>这一过程不是必须的，但是为了方便操作，最好在各个节点之间实现免密登陆，以下过程在所有的节点上执行：</p>
<p>① 生成秘钥对，输入以下命令，然后一路回车：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# ssh-keygen -t rsa</div></pre></td></tr></table></figure></p>
<p>② 将所有的公钥复制到<code>authorized_keys</code>文件中：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# cd ~/.ssh/</div><div class="line">[root@controller1 ~]# vim authorized_keys</div></pre></td></tr></table></figure></p>
<p>搜集每个节点上的<code>id_rsa.pub</code>文件内容，添加到<code>authorized_keys</code>文件中，然后保存退出。</p>
<p>③ 同样的过程，在剩余所有节点上执行一遍，然后修改<code>hosts</code>文件：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# vim /etc/hosts</div></pre></td></tr></table></figure></p>
<p>输入每个主机的<code>IP 主机名</code>，然后退出保存。</p>
<p>④ 验证是否成功：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# ssh controller2</div></pre></td></tr></table></figure></p>
<h4 id="六、安装依赖包"><a href="#六、安装依赖包" class="headerlink" title="六、安装依赖包"></a>六、安装依赖包</h4><p>以下过程在所有节点上都：</p>
<p>安装<code>epel-release</code>、<code>pip</code>、<code>git</code>：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# yum install -y epel-release python-pip git</div></pre></td></tr></table></figure></p>
<p>如果安装过程特别慢，可以考虑更换软件源，以下是Centos7更换阿里云源的方法：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak</div><div class="line">wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo</div><div class="line">或者：</div><div class="line">curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo</div></pre></td></tr></table></figure></p>
<p>升级<code>pip</code>到最新版：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# pip install -U pip</div></pre></td></tr></table></figure></p>
<p>如果pip下载包也比较慢，可以更换<code>pip</code>的源为豆瓣源或者阿里云源，以下以更换为阿里云源为例：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# mkdir -p ~/.pip</div><div class="line">[root@controller1 ~]# vim ~/.pip/pip.conf</div><div class="line">// 添加以下内容：</div><div class="line">[global]</div><div class="line">index-url = http://mirrors.aliyun.com/pypi/simple/</div><div class="line">[install]</div><div class="line">trusted-host=mirrors.aliyun.com</div></pre></td></tr></table></figure></p>
<p>安装其他的一些依赖：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# yum install python-devel libffi-devel gcc openssl-devel libselinux-python</div></pre></td></tr></table></figure></p>
<p><code>OpenStack</code>、<code>RabbitMQ</code>、<code>Ceph</code>等都对节点间的时间差有一定的要求，如果时间差过大，可能导致服务不能够正常运行，为此，我们最好能够安装<code>NTP</code>服务，让每个节点自动进行时间同步：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# yum install ntp</div><div class="line">[root@controller1 ~]# systemctl enable ntpd.service</div><div class="line">[root@controller1 ~]# systemctl start ntpd.service</div></pre></td></tr></table></figure></p>
<p>安装<code>ansible</code>，并升级到最新版：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# yum install ansible</div><div class="line">[root@controller1 ~]# pip install -U ansible</div></pre></td></tr></table></figure></p>
<p>停止<code>libvirt</code>组件，否则后面安装会失败：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# systemctl stop libvirtd.service</div><div class="line">[root@controller1 ~]# systemctl disable libvirtd.service</div></pre></td></tr></table></figure></p>
<p>安装最新版<code>Docker</code>，升级到最新版，然后检查Docker的版本：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# curl -sSL https://get.docker.io | bash</div><div class="line">[root@controller1 ~]# pip install -U docker</div><div class="line">[root@controller1 ~]# docker --version</div></pre></td></tr></table></figure></p>
<p>如果由于网络原因，以上安装方法<code>Docker</code>不能够成功安装，可以使用下面的方法进行安装：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line">// 设置repo</div><div class="line">[root@controller1 ~]# tee /etc/yum.repos.d/docker.repo &lt;&lt; &apos;EOF&apos;</div><div class="line">[dockerrepo]</div><div class="line">name=Docker Repository</div><div class="line">baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/</div><div class="line">enabled=1</div><div class="line">gpgcheck=1</div><div class="line">gpgkey=https://yum.dockerproject.org/gpg</div><div class="line">EOF</div><div class="line">// 安装Docker</div><div class="line">[root@controller1 ~]# yum install docker-engine docker-engine-selinux</div><div class="line">[root@controller1 ~]# pip install -U docker</div><div class="line">[root@controller1 ~]# docker --version</div></pre></td></tr></table></figure></p>
<p>对<code>Docker</code>进行配置：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# mkdir /etc/systemd/system/docker.service.d</div><div class="line">[root@controller1 ~]# tee /etc/systemd/system/docker.service.d/kolla.conf &lt;&lt;-&apos;EOF&apos;</div><div class="line">[Service]</div><div class="line">MountFlags=shared</div><div class="line">EOF</div></pre></td></tr></table></figure></p>
<p>重新加载守护进程，并重启<code>Docker</code>服务：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# systemctl daemon-reload</div><div class="line">[root@controller1 ~]# systemctl restart docker</div><div class="line">// 设置docker开机自启</div><div class="line">[root@controller1 ~]# systemctl enable docker</div></pre></td></tr></table></figure></p>
<p>为<code>Docker</code>配置访问私有仓库，修改<code>ExecStart</code>字段：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# vim /usr/lib/systemd/system/docker.service</div><div class="line">#ExecStart=/usr/bin/dockerd</div><div class="line">ExecStart=/usr/bin/dockerd --insecure-registry [SERVICE_IP]:4000</div></pre></td></tr></table></figure></p>
<p>其中<code>[SERVICE_IP]</code>换成你部署的私有仓库所在主机的<code>IP</code>，本次部署在<code>controller1</code>上，所以用<code>controller1</code>的<code>IP</code>。<br>重启<code>Docker</code>服务：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# systemctl daemon-reload</div><div class="line">[root@controller1 ~]# systemctl restart docker</div></pre></td></tr></table></figure></p>
<h4 id="七、配置Docker的私有仓库"><a href="#七、配置Docker的私有仓库" class="headerlink" title="七、配置Docker的私有仓库"></a>七、配置Docker的私有仓库</h4><p>限于国内网络环境的问题，如果直接在线安装很容易失败，所以我们非常有必要建立一个本地仓库。建立本地仓库所需要的OpenStack的各个组件的镜像，既可以通过<code>Kolla</code>进行<code>build</code>，也可以直接下载官网制作好的镜像。<br>运行<code>Registry</code>服务的容器，由于<code>5000</code>端口与<code>keystone</code>端口号冲突，所以我们需要修改其映射到本地<code>4000</code>端口上：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# docker run -d -v /opt/registry:/var/lib/registry -p 4000:5000 --restart=always --name registry registry:2</div><div class="line">// 查看是否成功启动</div><div class="line">[root@controller1 ~]# docker ps</div></pre></td></tr></table></figure></p>
<p>运行以上命令后，会自动在线拉取<code>registry:2</code>的镜像，如果因为网络环境不能够正常下载，也可以在一个网络状况比较好的机器上先下载好，然后导出为<code>.tar</code>包，再在相应的机器上导入：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">// 网络状况较好的机器上</div><div class="line">[root@localhost ~]# docker pull registry:2</div><div class="line">[root@localhost ~]# docker images</div><div class="line">[root@localhost ~]# docker save -o registry_v2.tar registry:2</div><div class="line">// 手动将 registry_v2.tar 包拷贝到目标机器上，然后导入</div><div class="line">[root@controller1 ~]# docker load -i ./registry_v2.tar</div><div class="line">[root@controller1 ~]# docker images</div></pre></td></tr></table></figure></p>
<p>当前机器内有了本地镜像了以后，在运行<code>docker run</code>，启动<code>registry</code>容器：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# docker run -d -v /opt/registry:/var/lib/registry -p 4000:5000 --restart=always --name registry registry:2</div><div class="line">// 查看是否正常启动</div><div class="line">[root@controller1 ~]# docker ps</div></pre></td></tr></table></figure></p>
<p>提前下载好官方的镜像包，本次使用：<code>centos-source-registry-ocata.tar.gz</code>,将其解压到：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">tar -zxvf centos-source-registry-ocata.tar.gz -C /opt/registry/</div></pre></td></tr></table></figure></p>
<p>在浏览器中输入：[SERVICE_IP]:4000/v2/_catalog，如果现实如下，则说明已经成功安装了本地仓库：<br><img src="http://img.blog.csdn.net/20171002195129769?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHVveGl1anVl/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="registry"></p>
<blockquote>
<p><strong><em>Reference:</em></strong></p>
<ul>
<li>OpenStack官方kolla镜像包下载地址：<a href="http://tarballs.openstack.org/kolla/images/" target="_blank" rel="external">http://tarballs.openstack.org/kolla/images/</a></li>
</ul>
<h4 id="八、安装Kolla-ansible部署工具"><a href="#八、安装Kolla-ansible部署工具" class="headerlink" title="八、安装Kolla-ansible部署工具"></a>八、安装Kolla-ansible部署工具</h4><p>此过程只需要在部署机上面执行，kolla-ansible既可以使用<code>pip</code>来安装，也可以通过<code>git</code>源码安装，本次通过源码安装：<br>下载源码包，一定要下载对应的版本，我们此次部署的是O版，所以下载O版的kolla-ansible：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# cd /opt</div><div class="line">[root@controller1 ~]# git clone http://git.trystack.cn/openstack/kolla-ansible –b stable/ocata</div></pre></td></tr></table></figure></p>
</blockquote>
<p>安装kolla-ansible：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# cd kolla-ansible</div><div class="line">[root@controller1 ~]# pip install ./</div></pre></td></tr></table></figure></p>
<p>复制配置文件和inventory文件：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# cp -r etc/kolla /etc/kolla/</div><div class="line">[root@controller1 ~]# cp -r ansible/inventory /home/inventory/</div></pre></td></tr></table></figure></p>
<p>如果是在虚拟机里装kolla，希望可以启动再启动虚拟机，那么你需要把virt_type=qemu，默认是kvm：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# mkdir -p /etc/kolla/config/nova</div><div class="line">[root@controller1 ~]# cat &lt;&lt; EOF &gt; /etc/kolla/config/nova/nova-compute.conf</div><div class="line">[libvirt]</div><div class="line">virt_type=qemu</div><div class="line">cpu_mode = none</div><div class="line">EOF</div></pre></td></tr></table></figure></p>
<p>生成密码文件：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# kolla-genpwd</div></pre></td></tr></table></figure></p>
<p>修改登录dashboard的admin用户的登录密码：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# vim /etc/kolla/passwords.yml</div><div class="line">// 修改以下字段</div><div class="line">keystone_admin_password: admin</div></pre></td></tr></table></figure></p>
<h4 id="九、开始部署"><a href="#九、开始部署" class="headerlink" title="九、开始部署"></a>九、开始部署</h4><p>由于我们采用的是多节点物理机部署，在部署之前，我们需要修改<code>globals.yml</code>和<code>multinode</code>两个配置文件。</p>
<p>① 修改<code>globals.yml</code><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# vim /etc/kolla/globalss.yml</div></pre></td></tr></table></figure></p>
<p>给出以下样例，附带部分相关说明：<br><figure class="highlight yaml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div><div class="line">143</div><div class="line">144</div><div class="line">145</div><div class="line">146</div><div class="line">147</div><div class="line">148</div><div class="line">149</div><div class="line">150</div><div class="line">151</div><div class="line">152</div><div class="line">153</div><div class="line">154</div><div class="line">155</div><div class="line">156</div><div class="line">157</div><div class="line">158</div><div class="line">159</div><div class="line">160</div><div class="line">161</div><div class="line">162</div><div class="line">163</div><div class="line">164</div><div class="line">165</div><div class="line">166</div><div class="line">167</div><div class="line">168</div><div class="line">169</div><div class="line">170</div><div class="line">171</div><div class="line">172</div><div class="line">173</div><div class="line">174</div><div class="line">175</div><div class="line">176</div><div class="line">177</div><div class="line">178</div><div class="line">179</div><div class="line">180</div><div class="line">181</div><div class="line">182</div><div class="line">183</div><div class="line">184</div><div class="line">185</div><div class="line">186</div><div class="line">187</div><div class="line">188</div><div class="line">189</div><div class="line">190</div><div class="line">191</div><div class="line">192</div><div class="line">193</div><div class="line">194</div><div class="line">195</div><div class="line">196</div><div class="line">197</div><div class="line">198</div><div class="line">199</div><div class="line">200</div><div class="line">201</div><div class="line">202</div><div class="line">203</div><div class="line">204</div><div class="line">205</div><div class="line">206</div><div class="line">207</div><div class="line">208</div><div class="line">209</div><div class="line">210</div><div class="line">211</div><div class="line">212</div><div class="line">213</div><div class="line">214</div><div class="line">215</div><div class="line">216</div><div class="line">217</div><div class="line">218</div><div class="line">219</div><div class="line">220</div><div class="line">221</div><div class="line">222</div><div class="line">223</div><div class="line">224</div><div class="line">225</div><div class="line">226</div><div class="line">227</div><div class="line">228</div><div class="line">229</div><div class="line">230</div><div class="line">231</div><div class="line">232</div><div class="line">233</div><div class="line">234</div><div class="line">235</div><div class="line">236</div><div class="line">237</div><div class="line">238</div><div class="line">239</div><div class="line">240</div><div class="line">241</div><div class="line">242</div><div class="line">243</div><div class="line">244</div><div class="line">245</div><div class="line">246</div><div class="line">247</div><div class="line">248</div><div class="line">249</div><div class="line">250</div><div class="line">251</div><div class="line">252</div><div class="line">253</div><div class="line">254</div><div class="line">255</div><div class="line">256</div><div class="line">257</div><div class="line">258</div><div class="line">259</div><div class="line">260</div><div class="line">261</div><div class="line">262</div><div class="line">263</div><div class="line">264</div><div class="line">265</div><div class="line">266</div><div class="line">267</div><div class="line">268</div><div class="line">269</div><div class="line">270</div><div class="line">271</div><div class="line">272</div><div class="line">273</div><div class="line">274</div><div class="line">275</div><div class="line">276</div><div class="line">277</div><div class="line">278</div><div class="line">279</div><div class="line">280</div><div class="line">281</div><div class="line">282</div><div class="line">283</div><div class="line">284</div><div class="line">285</div><div class="line">286</div><div class="line">287</div><div class="line">288</div><div class="line">289</div><div class="line">290</div><div class="line">291</div><div class="line">292</div><div class="line">293</div><div class="line">294</div><div class="line">295</div><div class="line">296</div><div class="line">297</div><div class="line">298</div><div class="line">299</div><div class="line">300</div><div class="line">301</div><div class="line">302</div><div class="line">303</div><div class="line">304</div><div class="line">305</div><div class="line">306</div><div class="line">307</div><div class="line">308</div><div class="line">309</div><div class="line">310</div><div class="line">311</div><div class="line">312</div><div class="line">313</div><div class="line">314</div><div class="line">315</div><div class="line">316</div><div class="line">317</div><div class="line">318</div><div class="line">319</div><div class="line">320</div><div class="line">321</div><div class="line">322</div><div class="line">323</div><div class="line">324</div><div class="line">325</div><div class="line">326</div><div class="line">327</div><div class="line">328</div><div class="line">329</div><div class="line">330</div><div class="line">331</div><div class="line">332</div><div class="line">333</div><div class="line">334</div><div class="line">335</div><div class="line">336</div><div class="line">337</div><div class="line">338</div><div class="line">339</div><div class="line">340</div><div class="line">341</div><div class="line">342</div><div class="line">343</div><div class="line">344</div><div class="line">345</div><div class="line">346</div></pre></td><td class="code"><pre><div class="line"><span class="meta">---</span></div><div class="line"><span class="comment">###################</span></div><div class="line"><span class="comment"># Kolla options</span></div><div class="line"><span class="comment">###################</span></div><div class="line"><span class="comment"># Valid options are [ COPY_ONCE, COPY_ALWAYS ]</span></div><div class="line"><span class="comment">#config_strategy: "COPY_ALWAYS"</span></div><div class="line"></div><div class="line"><span class="comment"># Valid options are [ centos, oraclelinux, ubuntu ]</span></div><div class="line"><span class="comment"># 和我们使用的操作系统有关系，此处我们用的centos7，所以填写“centos”</span></div><div class="line"><span class="attr">kolla_base_distro:</span> <span class="string">"centos"</span> </div><div class="line"></div><div class="line"><span class="comment"># Valid options are [ binary, source ]</span></div><div class="line"><span class="comment"># 我们下载的官方镜像包是“source”类型的，如果是“binary”就改成“binary”</span></div><div class="line"><span class="attr">kolla_install_type:</span> <span class="string">"source"</span></div><div class="line"></div><div class="line"><span class="comment"># Valid option is Docker repository tag</span></div><div class="line"><span class="comment"># 这个可以看看官方镜像包中软件的tag是多少，我们下载的O版对应：4.0.3</span></div><div class="line"><span class="attr">openstack_release:</span> <span class="string">"4.0.3"</span></div><div class="line"></div><div class="line"><span class="comment"># Location of configuration overrides</span></div><div class="line"><span class="comment">#node_custom_config: "/etc/kolla/config"</span></div><div class="line"></div><div class="line"><span class="comment"># This should be a VIP, an unused IP on your network that will float between</span></div><div class="line"><span class="comment"># the hosts running keepalived for high-availability. When running an All-In-One</span></div><div class="line"><span class="comment"># without haproxy and keepalived, this should be the first IP on your</span></div><div class="line"><span class="comment"># 'network_interface' as set in the Networking section below.</span></div><div class="line"><span class="comment">#这个IP地址是和em1网卡在同一个网段，但是没有使用的地址，用来做HA的绑定地址</span></div><div class="line"><span class="attr">kolla_internal_vip_address:</span> <span class="string">"xxx.xxx.xxx.xxx"</span></div><div class="line"></div><div class="line"><span class="comment"># This is the DNS name that maps to the kolla_internal_vip_address VIP. By</span></div><div class="line"><span class="comment"># default it is the same as kolla_internal_vip_address.</span></div><div class="line"><span class="comment">#kolla_internal_fqdn: "&#123;&#123; kolla_internal_vip_address &#125;&#125;"</span></div><div class="line"></div><div class="line"><span class="comment"># This should be a VIP, an unused IP on your network that will float between</span></div><div class="line"><span class="comment"># the hosts running keepalived for high-availability. It defaults to the</span></div><div class="line"><span class="comment"># kolla_internal_vip_address, allowing internal and external communication to</span></div><div class="line"><span class="comment"># share the same address.  Specify a kolla_external_vip_address to separate</span></div><div class="line"><span class="comment"># internal and external requests between two VIPs.</span></div><div class="line"><span class="comment">#kolla_external_vip_address: "&#123;&#123; kolla_internal_vip_address &#125;&#125;"</span></div><div class="line"></div><div class="line"><span class="comment"># The Public address used to communicate with OpenStack as set in the public_url</span></div><div class="line"><span class="comment"># for the endpoints that will be created. This DNS name should map to</span></div><div class="line"><span class="comment"># kolla_external_vip_address.</span></div><div class="line"><span class="comment">#kolla_external_fqdn: "&#123;&#123; kolla_external_vip_address &#125;&#125;"</span></div><div class="line"></div><div class="line"><span class="comment">####################</span></div><div class="line"><span class="comment"># Docker options</span></div><div class="line"><span class="comment">####################</span></div><div class="line"><span class="comment"># Below is an example of a private repository with authentication. Note the</span></div><div class="line"><span class="comment"># Docker registry password can also be set in the passwords.yml file.</span></div><div class="line"></div><div class="line"><span class="comment">#填写本地仓库的运行的服务器地址+端口号</span></div><div class="line"><span class="attr">docker_registry:</span> <span class="string">"[SERVICE_IP]:4000"</span></div><div class="line"><span class="comment">#如果使用的是OpenStack官方的镜像包，此项必须为：“lokolla”</span></div><div class="line"><span class="attr">docker_namespace:</span> <span class="string">"lokolla"</span></div><div class="line"><span class="comment">#docker_registry_username: "sam"</span></div><div class="line"><span class="comment">#docker_registry_password: "correcthorsebatterystaple"</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">###############################</span></div><div class="line"><span class="comment"># Neutron - Networking Options</span></div><div class="line"><span class="comment">###############################</span></div><div class="line"><span class="comment"># This interface is what all your api services will be bound to by default.</span></div><div class="line"><span class="comment"># Additionally, all vxlan/tunnel and storage network traffic will go over this</span></div><div class="line"><span class="comment"># interface by default. This interface must contain an IPv4 address.</span></div><div class="line"><span class="comment"># It is possible for hosts to have non-matching names of interfaces - these can</span></div><div class="line"><span class="comment"># be set in an inventory file per host or per group or stored separately, see</span></div><div class="line"><span class="comment">#     http://docs.ansible.com/ansible/intro_inventory.html</span></div><div class="line"><span class="comment"># Yet another way to workaround the naming problem is to create a bond for the</span></div><div class="line"><span class="comment"># interface on all hosts and give the bond name here. Similar strategy can be</span></div><div class="line"><span class="comment"># followed for other types of interfaces.</span></div><div class="line"><span class="comment">#此处配置第一块网卡，也是其他未制定网卡的Interface的默认选项</span></div><div class="line"><span class="attr">network_interface:</span> <span class="string">"em1"</span></div><div class="line"></div><div class="line"><span class="comment"># These can be adjusted for even more customization. The default is the same as</span></div><div class="line"><span class="comment"># the 'network_interface'. These interfaces must contain an IPv4 address.</span></div><div class="line"><span class="comment">#kolla_external_vip_interface: "&#123;&#123; network_interface &#125;&#125;"</span></div><div class="line"><span class="comment">#api_interface: "&#123;&#123; network_interface &#125;&#125;"</span></div><div class="line"><span class="comment">#Ceph数据传输专用网卡,此项最好为万兆网卡，以提升总体性能</span></div><div class="line"><span class="attr">storage_interface:</span> <span class="string">"p5p2"</span></div><div class="line"><span class="attr">cluster_interface:</span> <span class="string">"p5p2"</span></div><div class="line"><span class="comment">#tunnel_interface: "&#123;&#123; network_interface &#125;&#125;"</span></div><div class="line"><span class="comment">#dns_interface: "&#123;&#123; network_interface &#125;&#125;"</span></div><div class="line"></div><div class="line"><span class="comment"># This is the raw interface given to neutron as its external network port. Even</span></div><div class="line"><span class="comment"># though an IP address can exist on this interface, it will be unusable in most</span></div><div class="line"><span class="comment"># configurations. It is recommended this interface not be configured with any IP</span></div><div class="line"><span class="comment"># addresses for that reason.</span></div><div class="line"><span class="comment">#floatingIP用来外转数据包的网卡，就是我们空出来，没有配置IP的那个网卡</span></div><div class="line"><span class="attr">neutron_external_interface:</span> <span class="string">"em2"</span></div><div class="line"></div><div class="line"><span class="comment"># Valid options are [ openvswitch, linuxbridge ]</span></div><div class="line"><span class="comment">#neutron_plugin_agent: "openvswitch"</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">####################</span></div><div class="line"><span class="comment"># keepalived options</span></div><div class="line"><span class="comment">####################</span></div><div class="line"><span class="comment"># Arbitrary unique number from 0..255</span></div><div class="line"><span class="comment">#keepalived_virtual_router_id: "51"</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">####################</span></div><div class="line"><span class="comment"># TLS options</span></div><div class="line"><span class="comment">####################</span></div><div class="line"><span class="comment"># To provide encryption and authentication on the kolla_external_vip_interface,</span></div><div class="line"><span class="comment"># TLS can be enabled.  When TLS is enabled, certificates must be provided to</span></div><div class="line"><span class="comment"># allow clients to perform authentication.</span></div><div class="line"><span class="comment">#kolla_enable_tls_external: "no"</span></div><div class="line"><span class="comment">#kolla_external_fqdn_cert: "&#123;&#123; node_config_directory &#125;&#125;/certificates/haproxy.pem"</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">####################</span></div><div class="line"><span class="comment"># OpenStack options</span></div><div class="line"><span class="comment">####################</span></div><div class="line"><span class="comment"># Use these options to set the various log levels across all OpenStack projects</span></div><div class="line"><span class="comment"># Valid options are [ True, False ]</span></div><div class="line"><span class="comment">#openstack_logging_debug: "False"</span></div><div class="line"></div><div class="line"><span class="comment"># Valid options are [ novnc, spice ]</span></div><div class="line"><span class="comment">#nova_console: "novnc"</span></div><div class="line"></div><div class="line"><span class="comment"># OpenStack services can be enabled or disabled with these options</span></div><div class="line"><span class="comment"># 以下选项根据自己想要安装的OpenStack组件，把相应选项前的注释去掉即可</span></div><div class="line"><span class="attr">enable_aodh:</span> <span class="string">"yes"</span></div><div class="line"><span class="comment">#enable_barbican: "no"</span></div><div class="line"><span class="attr">enable_ceilometer:</span> <span class="string">"yes"</span></div><div class="line"><span class="comment">#enable_central_logging: "no"</span></div><div class="line"><span class="attr">enable_ceph:</span> <span class="string">"yes"</span></div><div class="line"><span class="comment">#如果用ceph作为swift的后端存储，enable_ceph_rgw必须为yes</span></div><div class="line"><span class="attr">enable_ceph_rgw:</span> <span class="string">"yes"</span></div><div class="line"><span class="comment">#enable_chrony: "no"</span></div><div class="line"><span class="attr">enable_cinder:</span> <span class="string">"yes"</span></div><div class="line"><span class="comment">#enable_cinder_backend_hnas_iscsi: "no"</span></div><div class="line"><span class="comment">#enable_cinder_backend_hnas_nfs: "no"</span></div><div class="line"><span class="comment">#enable_cinder_backend_iscsi: "no"</span></div><div class="line"><span class="comment">#enable_cinder_backend_lvm: "no"</span></div><div class="line"><span class="comment">#enable_cinder_backend_nfs: "no"</span></div><div class="line"><span class="comment">#enable_cloudkitty: "no"</span></div><div class="line"><span class="comment">#enable_collectd: "no"</span></div><div class="line"><span class="comment">#enable_congress: "no"</span></div><div class="line"><span class="comment">#enable_designate: "no"</span></div><div class="line"><span class="comment">#enable_destroy_images: "no"</span></div><div class="line"><span class="comment">#enable_etcd: "no"</span></div><div class="line"><span class="attr">enable_freezer:</span> <span class="string">"yes"</span></div><div class="line"><span class="attr">enable_gnocchi:</span> <span class="string">"yes"</span></div><div class="line"><span class="comment">#enable_grafana: "no"</span></div><div class="line"><span class="attr">enable_heat:</span> <span class="string">"yes"</span></div><div class="line"><span class="attr">enable_horizon:</span> <span class="string">"yes"</span></div><div class="line"><span class="comment">#enable_horizon_cloudkitty: "&#123;&#123; enable_cloudkitty | bool &#125;&#125;"</span></div><div class="line"><span class="attr">enable_horizon_freezer:</span> <span class="string">"<span class="template-variable">&#123;&#123; enable_freezer | bool &#125;&#125;</span>"</span></div><div class="line"><span class="comment">#enable_horizon_ironic: "&#123;&#123; enable_ironic | bool &#125;&#125;"</span></div><div class="line"><span class="comment">#enable_horizon_karbor: "&#123;&#123; enable_karbor | bool &#125;&#125;"</span></div><div class="line"><span class="attr">enable_horizon_magnum:</span> <span class="string">"<span class="template-variable">&#123;&#123; enable_magnum | bool &#125;&#125;</span>"</span></div><div class="line"><span class="comment">#enable_horizon_manila: "&#123;&#123; enable_manila | bool &#125;&#125;"</span></div><div class="line"><span class="comment">#enable_horizon_mistral: "&#123;&#123; enable_mistral | bool &#125;&#125;"</span></div><div class="line"><span class="comment">#enable_horizon_murano: "&#123;&#123; enable_murano | bool &#125;&#125;"</span></div><div class="line"><span class="attr">enable_horizon_neutron_lbaas:</span> <span class="string">"<span class="template-variable">&#123;&#123; enable_neutron_lbaas | bool &#125;&#125;</span>"</span></div><div class="line"><span class="attr">enable_horizon_sahara:</span> <span class="string">"<span class="template-variable">&#123;&#123; enable_sahara | bool &#125;&#125;</span>"</span></div><div class="line"><span class="comment">#enable_horizon_searchlight: "&#123;&#123; enable_searchlight | bool &#125;&#125;"</span></div><div class="line"><span class="comment">#enable_horizon_senlin: "&#123;&#123; enable_senlin | bool &#125;&#125;"</span></div><div class="line"><span class="comment">#enable_horizon_solum: "&#123;&#123; enable_solum | bool &#125;&#125;"</span></div><div class="line"><span class="comment">#enable_horizon_tacker: "&#123;&#123; enable_tacker | bool &#125;&#125;"</span></div><div class="line"><span class="comment">#enable_horizon_trove: "&#123;&#123; enable_trove | bool &#125;&#125;"</span></div><div class="line"><span class="comment">#enable_horizon_watcher: "&#123;&#123; enable_watcher | bool &#125;&#125;"</span></div><div class="line"><span class="comment">#enable_influxdb: "no"</span></div><div class="line"><span class="comment">#enable_ironic: "no"</span></div><div class="line"><span class="comment">#enable_karbor: "no"</span></div><div class="line"><span class="comment">#enable_kuryr: "no"</span></div><div class="line"><span class="attr">enable_magnum:</span> <span class="string">"yes"</span></div><div class="line"><span class="comment">#enable_manila: "no"</span></div><div class="line"><span class="comment">#enable_manila_backend_generic: "no"</span></div><div class="line"><span class="comment">#enable_manila_backend_hnas: "no"</span></div><div class="line"><span class="comment">#enable_mistral: "no"</span></div><div class="line"><span class="attr">enable_mongodb:</span> <span class="string">"yes"</span></div><div class="line"><span class="comment">#enable_murano: "no"</span></div><div class="line"><span class="comment">#enable_multipathd: "no"</span></div><div class="line"><span class="comment">#enable_neutron_dvr: "yes"</span></div><div class="line"><span class="comment">#enable_neutron_lbaas: "yes"</span></div><div class="line"><span class="comment">#enable_neutron_fwaas: "yes"</span></div><div class="line"><span class="comment">#enable_neutron_qos: "yes"</span></div><div class="line"><span class="comment">#enable_neutron_agent_ha: "no"</span></div><div class="line"><span class="comment">#enable_neutron_vpnaas: "yes"</span></div><div class="line"><span class="comment">#enable_nova_serialconsole_proxy: "no"</span></div><div class="line"><span class="comment">#enable_octavia: "no"</span></div><div class="line"><span class="comment">#enable_panko: "no"</span></div><div class="line"><span class="comment">#enable_rally: "no"</span></div><div class="line"><span class="attr">enable_sahara:</span> <span class="string">"yes"</span></div><div class="line"><span class="comment">#enable_searchlight: "no"</span></div><div class="line"><span class="comment">#enable_senlin: "no"</span></div><div class="line"><span class="comment">#enable_solum: "no"</span></div><div class="line"><span class="comment">#这个如果开启了enable_ceph_rgw_keystone, enable_swift必须为no，两者只能启用一个</span></div><div class="line"><span class="comment">#enable_swift: "no"</span></div><div class="line"><span class="comment">#enable_telegraf: "no"</span></div><div class="line"><span class="comment">#enable_tacker: "no"</span></div><div class="line"><span class="comment">#enable_tempest: "no"</span></div><div class="line"><span class="comment">#enable_trove: "no"</span></div><div class="line"><span class="comment">#enable_vmtp: "no"</span></div><div class="line"><span class="comment">#enable_watcher: "yes"</span></div><div class="line"></div><div class="line"><span class="comment">###################</span></div><div class="line"><span class="comment"># Ceph options</span></div><div class="line"><span class="comment">###################</span></div><div class="line"><span class="comment"># Ceph can be setup with a caching to improve performance. To use the cache you</span></div><div class="line"><span class="comment"># must provide separate disks than those for the OSDs</span></div><div class="line"><span class="comment">#ceph_enable_cache: "no"</span></div><div class="line"><span class="comment"># Valid options are [ forward, none, writeback ]</span></div><div class="line"><span class="comment">#ceph_cache_mode: "writeback"</span></div><div class="line"></div><div class="line"><span class="comment"># A requirement for using the erasure-coded pools is you must setup a cache tier</span></div><div class="line"><span class="comment"># Valid options are [ erasure, replicated ]</span></div><div class="line"><span class="comment">#ceph_pool_type: "replicated"</span></div><div class="line"></div><div class="line"><span class="comment"># Integrate ceph rados object gateway with openstack keystone</span></div><div class="line"><span class="comment">#和enable_swift两个只能选择一个为“yes”</span></div><div class="line"><span class="attr">enable_ceph_rgw_keystone:</span> <span class="string">"yes"</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">##############################</span></div><div class="line"><span class="comment"># Keystone - Identity Options</span></div><div class="line"><span class="comment">##############################</span></div><div class="line"></div><div class="line"><span class="comment"># Valid options are [ uuid, fernet ]</span></div><div class="line"><span class="comment">#keystone_token_provider: 'uuid'</span></div><div class="line"></div><div class="line"><span class="comment"># Interval to rotate fernet keys by (in seconds). Must be an interval of</span></div><div class="line"><span class="comment"># 60(1 min), 120(2 min), 180(3 min), 240(4 min), 300(5 min), 360(6 min),</span></div><div class="line"><span class="comment"># 600(10 min), 720(12 min), 900(15 min), 1200(20 min), 1800(30 min),</span></div><div class="line"><span class="comment"># 3600(1 hour), 7200(2 hour), 10800(3 hour), 14400(4 hour), 21600(6 hour),</span></div><div class="line"><span class="comment"># 28800(8 hour), 43200(12 hour), 86400(1 day), 604800(1 week).</span></div><div class="line"><span class="comment">#fernet_token_expiry: 86400</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">#########################</span></div><div class="line"><span class="comment"># Glance - Image Options</span></div><div class="line"><span class="comment">#########################</span></div><div class="line"><span class="comment"># Configure image backend.</span></div><div class="line"><span class="comment"># 此处我们选择glance后端为file，因为ceph作为后端的时候，只能使用raw的镜像</span></div><div class="line"><span class="attr">glance_backend_file:</span> <span class="string">"yes"</span></div><div class="line"><span class="attr">glance_backend_ceph:</span> <span class="string">"no"</span></div><div class="line"></div><div class="line"><span class="comment">#######################</span></div><div class="line"><span class="comment"># Ceilometer options</span></div><div class="line"><span class="comment">#######################</span></div><div class="line"><span class="comment"># Valid options are [ mongodb, mysql, gnocchi ]</span></div><div class="line"><span class="comment"># 此时我们用gnocchi作为ceilometer的数据库，也可以选用mongodb</span></div><div class="line"><span class="attr">ceilometer_database_type:</span> <span class="string">"gnocchi"</span></div><div class="line"></div><div class="line"><span class="comment"># Valid options are [ mongodb, gnocchi, panko ]</span></div><div class="line"><span class="comment"># 此时我们用gnocchi作为ceilometer的数据库，也可以选用mongodb</span></div><div class="line"><span class="attr">ceilometer_event_type:</span> <span class="string">"gnocchi"</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">#######################</span></div><div class="line"><span class="comment"># Barbican options</span></div><div class="line"><span class="comment">#######################</span></div><div class="line"><span class="comment"># Valid options are [ simple_crypto, p11_crypto ]</span></div><div class="line"><span class="comment">#barbican_crypto_plugin: "simple_crypto"</span></div><div class="line"><span class="comment">#barbican_library_path: "/usr/lib/libCryptoki2_64.so"</span></div><div class="line"></div><div class="line"><span class="comment">#######################</span></div><div class="line"><span class="comment">## Panko options</span></div><div class="line"><span class="comment">#######################</span></div><div class="line"><span class="comment"># Valid options are [ mongodb, mysql ]</span></div><div class="line"><span class="comment">#panko_database_type: "mysql"</span></div><div class="line"></div><div class="line"><span class="comment">#######################</span></div><div class="line"><span class="comment"># Gnocchi options</span></div><div class="line"><span class="comment">#######################</span></div><div class="line"><span class="comment"># Valid options are [ file, ceph ]</span></div><div class="line"><span class="comment">#gnocchi_backend_storage: "&#123;&#123; 'ceph' if enable_ceph|bool else 'file' &#125;&#125;"</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">#################################</span></div><div class="line"><span class="comment"># Cinder - Block Storage Options</span></div><div class="line"><span class="comment">#################################</span></div><div class="line"><span class="comment"># Enable / disable Cinder backends</span></div><div class="line"><span class="comment">#用ceph作为cinder的后端存储</span></div><div class="line"><span class="attr">cinder_backend_ceph:</span> <span class="string">"<span class="template-variable">&#123;&#123; enable_ceph &#125;&#125;</span>"</span></div><div class="line"><span class="comment">#cinder_volume_group: "cinder-volumes"</span></div><div class="line"><span class="comment">#cinder_backup_driver: "nfs"</span></div><div class="line"><span class="comment">#cinder_backup_share: ""</span></div><div class="line"><span class="comment">#cinder_backup_mount_options_nfs: ""</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">#######################</span></div><div class="line"><span class="comment"># Designate options</span></div><div class="line"><span class="comment">#######################</span></div><div class="line"><span class="comment"># Valid options are [ bind9 ]</span></div><div class="line"><span class="attr">designate_backend:</span> <span class="string">"bind9"</span></div><div class="line"><span class="attr">designate_ns_record:</span> <span class="string">"sample.openstack.org"</span></div><div class="line"></div><div class="line"><span class="comment">#########################</span></div><div class="line"><span class="comment"># Nova - Compute Options</span></div><div class="line"><span class="comment">#########################</span></div><div class="line"><span class="comment">#用ceph作为nova的后端存储</span></div><div class="line"><span class="attr">nova_backend_ceph:</span> <span class="string">"<span class="template-variable">&#123;&#123; enable_ceph &#125;&#125;</span>"</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">##############################</span></div><div class="line"><span class="comment"># Horizon - Dashboard Options</span></div><div class="line"><span class="comment">##############################</span></div><div class="line"><span class="comment">#horizon_backend_database: "&#123;&#123; enable_murano | bool &#125;&#125;"</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">#######################################</span></div><div class="line"><span class="comment"># Manila - Shared File Systems Options</span></div><div class="line"><span class="comment">#######################################</span></div><div class="line"><span class="comment"># HNAS backend configuration</span></div><div class="line"><span class="comment">#hnas_ip:</span></div><div class="line"><span class="comment">#hnas_user:</span></div><div class="line"><span class="comment">#hnas_password:</span></div><div class="line"><span class="comment">#hnas_evs_id:</span></div><div class="line"><span class="comment">#hnas_evs_ip:</span></div><div class="line"><span class="comment">#hnas_file_system_name:</span></div><div class="line"></div><div class="line"><span class="comment">##################################</span></div><div class="line"><span class="comment"># Swift - Object Storage Options</span></div><div class="line"><span class="comment">##################################</span></div><div class="line"><span class="comment"># Swift expects block devices to be available for storage. Two types of storage</span></div><div class="line"><span class="comment"># are supported: 1 - storage device with a special partition name and filesystem</span></div><div class="line"><span class="comment"># label, 2 - unpartitioned disk  with a filesystem. The label of this filesystem</span></div><div class="line"><span class="comment"># is used to detect the disk which Swift will be using.</span></div><div class="line"></div><div class="line"><span class="comment"># Swift support two mathcing modes, valid options are [ prefix, strict ]</span></div><div class="line"><span class="comment">#swift_devices_match_mode: "strict"</span></div><div class="line"></div><div class="line"><span class="comment"># This parameter defines matching pattern: if "strict" mode was selected,</span></div><div class="line"><span class="comment"># for swift_devices_match_mode then swift_device_name should specify the name of</span></div><div class="line"><span class="comment"># the special swift partition for example: "KOLLA_SWIFT_DATA", if "prefix" mode was</span></div><div class="line"><span class="comment"># selected then swift_devices_name should specify a pattern which would match to</span></div><div class="line"><span class="comment"># filesystems' labels prepared for swift.</span></div><div class="line"><span class="comment">#swift_devices_name: "KOLLA_SWIFT_DATA"</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">################################################</span></div><div class="line"><span class="comment"># Tempest - The OpenStack Integration Test Suite</span></div><div class="line"><span class="comment">################################################</span></div><div class="line"><span class="comment"># following value must be set when enable tempest</span></div><div class="line"><span class="attr">tempest_image_id:</span></div><div class="line"><span class="attr">tempest_flavor_ref_id:</span></div><div class="line"><span class="attr">tempest_public_network_id:</span></div><div class="line"><span class="attr">tempest_floating_network_name:</span></div><div class="line"></div><div class="line"><span class="comment"># tempest_image_alt_id: "&#123;&#123; tempest_image_id &#125;&#125;"</span></div><div class="line"><span class="comment"># tempest_flavor_ref_alt_id: "&#123;&#123; tempest_flavor_ref_id &#125;&#125;"</span></div></pre></td></tr></table></figure></p>
<p>② 配置<code>multinode</code>文件，这个文件主要是指定物理节点的角色，供ansible使用：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# vim /home/inventory/multinode</div></pre></td></tr></table></figure></p>
<p>给出如下样例：<br><figure class="highlight yaml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div></pre></td><td class="code"><pre><div class="line"><span class="comment"># These initial groups are the only groups required to be modified. The</span></div><div class="line"><span class="comment"># additional groups are for more control of the environment.</span></div><div class="line"><span class="string">[control]</span></div><div class="line"><span class="comment"># These hostname must be resolvable from your deployment host</span></div><div class="line"><span class="string">controller1</span></div><div class="line"><span class="string">controller2</span></div><div class="line"><span class="string">controller3</span></div><div class="line"></div><div class="line"><span class="comment"># The above can also be specified as follows:</span></div><div class="line"><span class="comment">#control[01:03]     ansible_user=kolla</span></div><div class="line"></div><div class="line"><span class="comment"># The network nodes are where your l3-agent and loadbalancers will run</span></div><div class="line"><span class="comment"># This can be the same as a host in the control group</span></div><div class="line"><span class="string">[network]</span></div><div class="line"><span class="string">controller1</span></div><div class="line"><span class="string">controller2</span></div><div class="line"><span class="string">controller3</span></div><div class="line"></div><div class="line"><span class="string">[compute]</span></div><div class="line"><span class="string">compute1</span></div><div class="line"><span class="string">compute2</span></div><div class="line"><span class="string">compute3</span></div><div class="line"><span class="string">compute4</span></div><div class="line"><span class="string">compute5</span></div><div class="line"><span class="string">compute6</span></div><div class="line"><span class="string">compute7</span></div><div class="line"><span class="string">compute8</span></div><div class="line"><span class="string">compute9</span></div><div class="line"></div><div class="line"><span class="string">[monitoring]</span></div><div class="line"><span class="string">controller1</span></div><div class="line"></div><div class="line"><span class="comment"># When compute nodes and control nodes use different interfaces,</span></div><div class="line"><span class="comment"># you can specify "api_interface" and other interfaces like below:</span></div><div class="line"><span class="comment">#compute01 neutron_external_interface=eth0 api_interface=em1 storage_interface=em1 tunnel_interface=em1</span></div><div class="line"></div><div class="line"><span class="string">[storage]</span></div><div class="line"><span class="string">controller1</span></div><div class="line"><span class="string">controller2</span></div><div class="line"><span class="string">controller3</span></div><div class="line"><span class="string">compute1</span></div><div class="line"><span class="string">compute2</span></div><div class="line"><span class="string">compute3</span></div><div class="line"><span class="string">compute4</span></div><div class="line"><span class="string">compute5</span></div><div class="line"><span class="string">compute6</span></div><div class="line"><span class="string">compute7</span></div><div class="line"><span class="string">compute8</span></div><div class="line"><span class="string">compute9</span></div><div class="line"></div><div class="line"><span class="comment"># 以下剩余的部分不需要修改</span></div></pre></td></tr></table></figure></p>
<p>③ 为安装Ceph准备OSD节点，在所有的存储节点上执行如下命令，此次我们以有两块数据盘 <code>sdb</code>、<code>sdc</code>为例：<br>格式化<code>sdb</code>数据盘：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# parted /dev/sdb -s -- mklabel gpt mkpart KOLLA_CEPH_OSD_BOOTSTRAP 1 -1</div><div class="line">[root@controller1 ~]# parted /dev/sdb print</div><div class="line">Model: VMware, VMware Virtual S (scsi)</div><div class="line">Disk /dev/sdb: 500GB</div><div class="line">Sector size (logical/physical): 512B/512B</div><div class="line">Partition Table: gpt</div><div class="line">Number  Start   End     Size    File system  Name                      Flags</div><div class="line">     1      1049kB  10.7GB  10.7GB               KOLLA_CEPH_OSD_BOOTSTRAP</div></pre></td></tr></table></figure></p>
<p>格式化<code>sdc</code>数据盘：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# parted /dev/sdc -s -- mklabel gpt mkpart KOLLA_CEPH_OSD_BOOTSTRAP 1 -1</div><div class="line">[root@controller1 ~]# parted /dev/sdc print</div><div class="line">Model: VMware, VMware Virtual S (scsi)</div><div class="line">Disk /dev/sdc: 500GB</div><div class="line">Sector size (logical/physical): 512B/512B</div><div class="line">Partition Table: gpt</div><div class="line">Number  Start   End     Size    File system  Name                      Flags</div><div class="line">     1      1049kB  10.7GB  10.7GB               KOLLA_CEPH_OSD_BOOTSTRAP</div></pre></td></tr></table></figure></p>
<p>④ 部署前检查，只需要在部署节点上执行如下命令：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# kolla-ansible prechecks -i /home/inventory/multinode</div></pre></td></tr></table></figure></p>
<p>这时候，kolla会自动对配置文件，和当前机器的部署环境做检测，如果全是<code>ok</code>，那就可以开始部署，如果出现了<code>fail</code>可以根据相应的提示，查找问题并是修复，然后再检查一遍，如此循环，直到全部<code>ok</code>为止。预计执行大概需要半个小时，如果相看详细的输出日志，可以在命令后面加上<code>-vvv</code>。</p>
<p>④ 开始部署，只需要在部署节点上执行如下命令：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# kolla-ansible deploy -i /home/inventory/multinode</div></pre></td></tr></table></figure></p>
<p>这时候，kolla便开始自动从本地仓库中拉取相应的镜像，在<code>/etc/kolla/</code>目录下生成各个组件的配置文件，根据配置文件启动相应的组件的<code>container</code>并调用<code>kolla_start</code>脚本进行初始化，然后配置各个服务的<code>endpoint</code>地址，最终完成<code>OpenStack</code>的安装。首次执行需要拉取镜像，时间会比较长，以后每次重复执行不需要拉取镜像，大概运行时间为半个小时左右，如果想看详细的日志信息，可以在命令后面加上<code>-vvv</code>。</p>
<p>⑤ 部署过程中如果遇到什么错误导致了<code>fail</code>，可以先看看输出信息，是否能够定位到具体的问题，如果可以则修复问题，如果没有什么头绪，可以直接重试运行上述命令，进行再次部署，基本可能会成功，如果问题重复出现，则需要好好看看输出日志，找找问题所在并修复。</p>
<p>⑥ 成功部署后，可以通过如下命令查看是否所有的<code>container</code>都在正常运行：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# docker ps -a</div></pre></td></tr></table></figure></p>
<p>如果都正常，可以在浏览器中输入你再<code>globals.yml</code>制定的<code>kolla_internal_vip_address</code>的IP地址来访问<code>dashboard</code>。用户名为：<code>admin</code>，登陆密码为你再<code>passwords.yml</code>中制定的<code>keystone_admin_password</code>字段的值。</p>
<p>⑦ 如果想要增加组件，可以直接修改<code>globals.yml</code>文件中的配置项，然后运行④中的命令。</p>
<p>⑧ 如果想要重新部署，可以使用如下命令清理环境，然后再次运行④中的命令：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# kolla-ansible destroy -i /home/inventory/multinode</div></pre></td></tr></table></figure></p>
<p>会有一个提示你确认的过程，只需要按照它的提示，输入相应的命令选项确认即可。</p>
<blockquote>
<p><strong><em>Note:</em></strong><br>在执行<code>destroy</code>命令之前一定要确保，当前OpenStack平台上没有存储镜像，也没有相应的<code>instance</code>和<code>volume</code>,也没有swift的存储空间，总而言之，OpenStack上面除了配置选项外，不能存有任何额外的东西，否则会导致清理环境失败。<strong>这点一定要切记，很重要！！！</strong></p>
</blockquote>
<p>如果使用的Ceph储存，还需要删除相应的挂在盘并重新打上<code>OSD</code>标签，此处以有<code>sdb</code>，<code>sdc</code>两块数据盘为例：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">//查看当前</div><div class="line">[root@controller1 ~]# df -h</div><div class="line">......</div><div class="line">/dev/sdb1   495G   41M  495G   1% /var/lib/ceph/osd/40d7390c-43d5-48f9-ad94-9cd59393b111</div><div class="line">/dev/sdc1   495G   41M  495G   1% /var/lib/ceph/osd/2d4f594e-5212-4fcc-ada3-e9553f7c8050</div><div class="line">......</div><div class="line"></div><div class="line">//卸载这两块盘</div><div class="line">[root@controller1 ~]# umount /dev/sdb1</div><div class="line">[root@controller1 ~]# umount /dev/sdc1</div><div class="line"></div><div class="line">//重新为两块盘打上OSD标签</div><div class="line">[root@controller1 ~]# parted /dev/sdb -s -- mklabel gpt mkpart KOLLA_CEPH_OSD_BOOTSTRAP 1 -1</div><div class="line">[root@controller1 ~]# parted /dev/sdc -s -- mklabel gpt mkpart KOLLA_CEPH_OSD_BOOTSTRAP 1 -1</div></pre></td></tr></table></figure></p>
<p>此时部署环境已经准备好，再次运行④中的命令，进行部署，非常方便。</p>
<h4 id="十、验证部署并初始化"><a href="#十、验证部署并初始化" class="headerlink" title="十、验证部署并初始化"></a>十、验证部署并初始化</h4><p>部署完成后，我们需要进行验证，会在<code>/etc/kolla</code>目录下生成<code>admin-openrc.sh</code>文件：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# kolla-ansible post-deploy</div></pre></td></tr></table></figure></p>
<p>安装OpenStack的client端：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# pip install python-openstackclient</div></pre></td></tr></table></figure></p>
<p>编辑初始化脚本文件<code>/usr/share/kolla-ansible/init-runonce</code>：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# vim /usr/share/kolla-ansible/init-runonce</div><div class="line">// 修改一下部分</div><div class="line">EXT_NET_CIDR=&apos;192.168.12.0/24&apos;</div><div class="line">EXT_NET_RANGE=&apos;start=192.168.12.30,end=192.168.12.40&apos;</div><div class="line">EXT_NET_GATEWAY=&apos;192.168.12.1&apos;</div></pre></td></tr></table></figure></p>
<blockquote>
<p><strong><em>Note:</em></strong><br>192.168.12.0只是一个示例网络，这个网络是给VM的floatingIP来用，就是我上面em2接的网络，这个网络需要可以通过路由器访问互联网，并且能够远程SSH。此处的IP地址请根据自己的实际情况修改。</p>
</blockquote>
<p>运行初始化脚本，进行初始化：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[root@controller1 ~]# source /etc/kolla/admin-openrc.sh</div><div class="line">[root@controller1 ~]# cd /usr/share/kolla-ansible</div><div class="line">[root@controller1 ~]# ./init-runonce</div></pre></td></tr></table></figure></p>
<blockquote>
<p><strong><em>Note:</em></strong><br>上面这个初试化过程中需要从<code>http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img</code>下载一个测试镜像，限于网络原因，有可能下载很慢或者下载失败，我们可以手动用下载工作下载好，放到<code>/usr/share/</code>目录下，这样，脚本就会检测到已经下载完成，不会再进行下载，直接上传。</p>
</blockquote>
<p>可以根据脚本最后运行完的提示运行如下命令，创建一个VM：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">openstack server create \</div><div class="line">    --image cirros \</div><div class="line">    --flavor m1.tiny \</div><div class="line">    --key-name mykey \</div><div class="line">    --nic net-id=2ba93782-71e2-44d6-ad64-796c5853dcce \</div><div class="line">    demo1</div></pre></td></tr></table></figure></p>
<p>登陆dashboard，正常使用OpenStack。</p>
<h4 id="十一、附Docker常用命令："><a href="#十一、附Docker常用命令：" class="headerlink" title="十一、附Docker常用命令："></a>十一、附Docker常用命令：</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div></pre></td><td class="code"><pre><div class="line">// 列出当前宿主机上已有的镜像</div><div class="line">[root@controller1 ~]# docker images</div><div class="line">// 在docker index中搜索image</div><div class="line">[root@controller1 ~]# docker search IMAGE_NAME</div><div class="line">// 从docker registry server 中下拉image或repository，只写名字为从官方hub拉取</div><div class="line">[root@controller1 ~]# docker pull [SERVICE_IP]:4000/mongo:latest</div><div class="line">// 推送一个image或repository到registry</div><div class="line">[root@controller1 ~]# docker push [SERVICE_IP]:4000/mongo:2014-10-27</div><div class="line">// 从image启动一个container</div><div class="line">[root@controller1 ~]# docker run [OPTIONS] IMAGE [COMMAND] [ARG...]</div><div class="line">// 将一个container固化为一个新的image</div><div class="line">[root@controller1 ~]# docker commit &lt;container&gt; [repo:tag]</div><div class="line">// 开启/停止/重启container（start/stop/restart）</div><div class="line">[root@controller1 ~]# docker start/stop/restart CONTAINER_ID</div><div class="line">// 查看image或container的底层信息（inspect）</div><div class="line">[root@controller1 ~]# docker inspect CONTAINER_ID</div><div class="line">// 删除一个或多个container</div><div class="line">[root@controller1 ~]# docker rm &lt;container_id/contaner_name&gt;</div><div class="line">// 删除所有停止的容器</div><div class="line">[root@controller1 ~]# docker rm $(docker ps -a -q)</div><div class="line">// 删除一个或多个image</div><div class="line">[root@controller1 ~]# docker rmi &lt;image_id/image_name ...&gt;</div><div class="line">// 查看容器的信息container</div><div class="line">[root@controller1 ~]# docker ps -a</div><div class="line">// 查看容器中正在运行的进程</div><div class="line">[root@controller1 ~]# docker top CONTAINER_ID</div><div class="line">// 查看容器的运行日志</div><div class="line">[root@controller1 ~]# docker logs CONTAINER_ID</div><div class="line">// 导出当前宿主机上已有的镜像</div><div class="line">[root@controller1 ~]# docker save -o NAME.tar IMAGE_NAEM:TAG</div><div class="line">// 导入已有的镜像tar包</div><div class="line">[root@controller1 ~]# docker Load -i NAME.tar</div><div class="line">// 以root权限登陆container内部</div><div class="line">[root@controller1 ~]# docker exec -it -u root CONTAINER_ID /bin/bash</div></pre></td></tr></table></figure>
<h4 id="十二、参考资料"><a href="#十二、参考资料" class="headerlink" title="十二、参考资料"></a>十二、参考资料</h4><blockquote>
<p><strong><em>Reference：</em></strong></p>
<ul>
<li>官方文档：<a href="https://docs.openstack.org/kolla-ansible/latest/user/quickstart.html" target="_blank" rel="external">https://docs.openstack.org/kolla-ansible/latest/user/quickstart.html</a></li>
<li>Kolla安装Ocata 单节点：<a href="http://www.chenshake.com/kolla-installation/" target="_blank" rel="external">http://www.chenshake.com/kolla-installation/</a></li>
<li>OpenStack实战分享：Kolla多节点部署加Ceph后端：<a href="http://www.99cloud.net/html/2017/jiuzhouyuanchuang_0317/302.html" target="_blank" rel="external">http://www.99cloud.net/html/2017/jiuzhouyuanchuang_0317/302.html</a></li>
<li>Docker私有仓库Registry的搭建验证：<a href="http://www.cnblogs.com/lienhua34/p/4922130.html" target="_blank" rel="external">http://www.cnblogs.com/lienhua34/p/4922130.html</a></li>
<li>Jeffrey Zhang的blog：<a href="http://xcodest.me/" target="_blank" rel="external">http://xcodest.me/</a></li>
<li>kolla的一点心得：<a href="http://blog.csdn.net/pengdake300/article/details/54581499" target="_blank" rel="external">http://blog.csdn.net/pengdake300/article/details/54581499</a></li>
</ul>
</blockquote>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div></div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="/images/jok.png" alt="小马 WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
    </div>
  </div>


      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Openstack/" rel="tag"># Openstack</a>
          
            <a href="/tags/Kolla/" rel="tag"># Kolla</a>
          
            <a href="/tags/安装部署/" rel="tag"># 安装部署</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/05/24/修改Sahara源码后的部署问题/" rel="next" title="修改Sahara源码后的部署问题">
                <i class="fa fa-chevron-left"></i> 修改Sahara源码后的部署问题
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/10/03/Kolla相关零零碎碎/" rel="prev" title="Kolla相关零零碎碎">
                Kolla相关零零碎碎 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="cloud-tie-wrapper" class="cloud-tie-wrapper"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar1.jpg"
               alt="小马" />
          <p class="site-author-name" itemprop="name">小马</p>
           
              <p class="site-description motion-element" itemprop="description">假装不正经</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">11</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">2</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">21</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hanbert" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/BertHan" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  微博
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#一、Kolla部署OpenStack的架构"><span class="nav-number">1.</span> <span class="nav-text">一、Kolla部署OpenStack的架构</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#二、前期准备"><span class="nav-number">2.</span> <span class="nav-text">二、前期准备</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#三、网络环境准备"><span class="nav-number">3.</span> <span class="nav-text">三、网络环境准备</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#四、部署规划"><span class="nav-number">4.</span> <span class="nav-text">四、部署规划</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#五、配置免密登陆"><span class="nav-number">5.</span> <span class="nav-text">五、配置免密登陆</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#六、安装依赖包"><span class="nav-number">6.</span> <span class="nav-text">六、安装依赖包</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#七、配置Docker的私有仓库"><span class="nav-number">7.</span> <span class="nav-text">七、配置Docker的私有仓库</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#八、安装Kolla-ansible部署工具"><span class="nav-number">8.</span> <span class="nav-text">八、安装Kolla-ansible部署工具</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#九、开始部署"><span class="nav-number">9.</span> <span class="nav-text">九、开始部署</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#十、验证部署并初始化"><span class="nav-number">10.</span> <span class="nav-text">十、验证部署并初始化</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#十一、附Docker常用命令："><span class="nav-number">11.</span> <span class="nav-text">十一、附Docker常用命令：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#十二、参考资料"><span class="nav-number">12.</span> <span class="nav-text">十二、参考资料</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2016 - 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">小马</span>
</div>


<div class="powered-by">
   <a class="theme-link" href="https://www.hanbert.cn"> </a> 小马专属
</div>

<div class="theme-info">
  博客 -
  <a class="theme-link" href="https://www.hanbert.cn">
    记录我的生活
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  







  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  


  




	





  
    
    <script>
      var cloudTieConfig = {
        url: document.location.href, 
        sourceId: "",
        productKey: "a112af18c95445c591096a909c4fb62c",
        target: "cloud-tie-wrapper"
      };
    </script>
    <script src="https://img1.ws.126.net/f2e/tie/yun/sdk/loader.js"></script>
  










  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
      search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.popup').toggle();
    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';
      $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = $( "entry", xmlResponse ).map(function() {
            return {
              title: $( "title", this ).text(),
              content: $("content",this).text(),
              url: $( "url" , this).text()
            };
          }).get();
          var $input = document.getElementById(search_id);
          var $resultContent = document.getElementById(content_id);
          $input.addEventListener('input', function(){
            var matchcounts = 0;
            var str='<ul class=\"search-result-list\">';
            var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
            $resultContent.innerHTML = "";
            if (this.value.trim().length > 1) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var content_index = [];
                var data_title = data.title.trim().toLowerCase();
                var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                var data_url = decodeURIComponent(data.url);
                var index_title = -1;
                var index_content = -1;
                var first_occur = -1;
                // only match artiles with not empty titles and contents
                if(data_title != '') {
                  keywords.forEach(function(keyword, i) {
                    index_title = data_title.indexOf(keyword);
                    index_content = data_content.indexOf(keyword);
                    if( index_title >= 0 || index_content >= 0 ){
                      isMatch = true;
                      if (i == 0) {
                        first_occur = index_content;
                      }
                    }

                  });
                }
                // show search results
                if (isMatch) {
                  matchcounts += 1;
                  str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                  var content = data.content.trim().replace(/<[^>]+>/g,"");
                  if (first_occur >= 0) {
                    // cut out 100 characters
                    var start = first_occur - 20;
                    var end = first_occur + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if(start == 0){
                      end = 50;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    var match_content = content.substring(start, end);
                    // highlight all keywords
                    keywords.forEach(function(keyword){
                      var regS = new RegExp(keyword, "gi");
                      match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                    });

                    str += "<p class=\"search-result\">" + match_content +"...</p>"
                  }
                  str += "</li>";
                }
              })};
            str += "</ul>";
            if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
            if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
            $resultContent.innerHTML = str;
          });
          proceedsearch();
        }
      });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("PON7x61Hu1UYOgywYUN55ig8-gzGzoHsz", "1bzugjkBEuXCThr7Cro7lz6l");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  
  <!-- 背景动画 -->
  <div id="particles-js"></div>
  <script type="text/javascript" src="/js/src/particle.js"></script>
  <!-- <script src="js/app.js"></script> -->
  
</body>
</html>
